<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$setting=$return['pluginset'];
if($_RQ['op']=='main'){
	$return['ischecklogin']=model('core/core')->checklogin('','',true);
	$this->model('member')->checkmember();
	$return['groups']=pdo_getall('jy_51job_job_group',array('status'=>1,'uniacid'=>$_SESSION['uniacid']),array('id','title'),'','paixu desc,id desc');
	foreach($return['groups'] as &$item){
		$item['cids']=pdo_getall('jy_51job_job_group',array('pid'=>$item['id'],'status'=>1,'uniacid'=>$_SESSION['uniacid']),array('id','title'),'','paixu desc,id desc');
	}
	$setting['bankuai1'] = !empty($setting['bankuai1']) ? $setting['bankuai1'] : $bankuai1;
	$setting['footernav'] = !empty($setting['footernav']) ? $setting['footernav'] : $footernav;
	$return['pcd']=$this->session('pcd')?:array('city'=>'');
	if($return['pcd']){
		$address=$return['pcd']['province'].' '.$return['pcd']['city'];
		$code=pdo_getcolumn('core_area',array('address'=>$address),'parent_code');
	}
	$return['sharedata']=array(
		'title'=>$setting['share_title'],
		'desc'=>$setting['share_desc'],
		'link'=>custom_url('jy_51job/jianlist//code='.$code,true),
		'imgUrl'=>tomedia($setting['share_image']),
	);
	$sid=intval($_RQ['sid']);
	$cid=intval($_RQ['cid']);
	if($cid){
		$pid=pdo_getcolumn('jy_51job_job_group',array('id'=>$cid,'uniacid'=>$_SESSION['uniacid']),'pid');
		$pid=pdo_getcolumn('jy_51job_job_group',array('id'=>$pid,'uniacid'=>$_SESSION['uniacid']),'pid');
		if($pid){
			$sid=$cid;
			$cid=0;
		}
	}
	$return['params']=array('city'=>$return['pcd']['city'],'isjianli'=>1,'isbao'=>-1,'paytype'=>-1,'sex'=>-1,'xueli'=>-1,'pid'=>intval($_RQ['pid']),'cid'=>$cid,'sid'=>$sid);
	$return['setting']=$setting;
	$return['member']=pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('createtime','credit1','credit2','mobile','avatar','nickname'));
	$return['notices']=pdo_getall('core_account_article',array('uniacid'=>$_SESSION['uniacid'],'status'=>'1'),'','id desc');
	$return['xueli_type']=$this->xueli_type;
	$return['job_type']=$this->job_type;
	$return['job_isbao']=$this->job_isbao;
	$return['gongyear']=$this->gongyear;
	$return['job_isbao']=$this->job_isbao;
	set_html('title',$setting['title']?$setting['title'] :'灵活人才');
	exi($return);
}
// js 获取数据
if($_RQ['op']=='getlist'){
	$post=get_postdata();
	$params=array(
		'uniacid'=>$_SESSION['uniacid'],
	);
	if(trim($_RQ['keyword'])){
		$return['params']['keyword']=trim($_RQ['keyword']);
		$params['title like']='%'.trim($_RQ['keyword']).'%';
	}
	if($_RQ['pid']){
		$params['pid']=intval($_RQ['pid']);
		$return['params']['pid']=intval($_RQ['pid']);
	}
	if($_RQ['cid']){
		$params['cid']=intval($_RQ['cid']);
		$return['params']['cid']=intval($_RQ['cid']);
	}
	if($_RQ['sid']){
		$params['sid']=intval($_RQ['sid']);
		$return['params']['sid']=intval($_RQ['sid']);
	}
	if($_RQ['type']>0){
		$params['type']=intval($_RQ['type']);
	}
	if($_RQ['sex']>0){
		$params['sex']=intval($_RQ['sex']);
	}
	if($_RQ['xueli']>0){
		$params['xueli <=']=intval($_RQ['xueli']);
	}
	if($_RQ['cids']){
		$cids=str_array($_RQ['cids']);
		$params['cid']=$cids;
	}
	if($_RQ['city']){
		$_RQ['city']=str_replace('市','',$_RQ['city']);
		$params['city like']='%'.$_RQ['city'].'%';
		$return['params']['city']=$_RQ['city'];
	}
	if($_RQ['district']){
		$_RQ['district']=str_replace('区','',$_RQ['district']);
		$params['district like']='%'.$_RQ['district'].'%';
		$return['params']['district']=$_RQ['district'];
	}
	//print_r($params);exit;
	//进一步整理筛选条件，商品属性字段是否需 要调整，商品分类如何筛选，orderby如何整理
	$pindex = max(1, intval($_RQ['page']));
	$psize = 20;
	if(intval($_RQ['num'])){
		$psize=$_RQ['num'];
	}
	$total='';
	$fields=array('id','name','title','mid','pcd','gongzhi','gongyear','age','sex','xueli','type','pid','cids','createtime','express');
	$orderby='createtime desc';
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'fields'=>$fields,
		'orderby'=>$orderby,
	);
	if($_RQ['isjuli'] || $_RQ['isitem']){
		if($_RQ['page']>1){
			$list=array();
		}else{
			$list=pdo_getall('jy_51job_jianli',$params,$fields,'',$orderby);
		}
	}else{
		$list=pdo_getslice('jy_51job_jianli',$params,array($pindex,$psize),$total,$fields,'',$orderby);	
	}
	if($list){
		$year=date('Y');
		$year=intval($year);
		$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
		foreach($list as &$item){
			$item['pcd']=json_decode($item['pcd'],true);
			$item['member']=pdo_get('jy_51job_member',array('id'=>$_SESSION['memberid'],'uniacid'=>$_SESSION['uniacid']));
			if($item['createtime']>$daytime-2*24*3600){
				$item['isnew']=1;
			}
			if(!$item['isnew'] && $item['member']['logintime']>$daytime){
				$item['isday']=1;
			}
			if(!$item['age']){
				$item['age']=$item['member']['birth']>0?$year-intval($item['member']['birth']):'';
			}else{
				$item['age']=$year-$item['age'];
			}
			$item['typetitle']=$this->job_type[$item['type']];
			$item['xuelititle']=$this->job_type[$item['member']['xueli']];
			$item['createtime']=date('Y-m-d H:m:s',$item['createtime']);
			$item['cids']=str_array($item['cids']);
			$item['cidstitle']=array();
			foreach($item['cids'] as $cid){
				$item['cidstitle'][]=pdo_getcolumn('jy_51job_job_group',array('id'=>$cid,'uniacid'=>$_SESSION['uniacid']),'title');
			}
		}
	}
	if($_RQ['isjuli']){
		paixu($list,'juli','asc');
	}
	$return['list']=$list;
	exi($return);
}
?>